'''
Created on Jan 26, 2010

@author: christianp
'''
import unittest
from UTestData import UTestData
from BruTile.AxisNormal import AxisNormal
from BruTile.Extent import Extent
from BruTile.TileRange import TileRange
from BruTile.TileInfo import TileInfo

class UAxis(unittest.TestCase):
    
    axisnormal = AxisNormal()
    tile_range = TileRange(0,0,0,0)
    schema = UTestData.create_tile_schema()
    extent = Extent(-12050000.0,-9425000.0,12050000.0, 9425000.0)
    level = 2
    
    def test_world_to_tile(self):
        print("UAxis: test_world_to_tile")
        self.tile_range = self.axisnormal.world_to_tile(self.extent, self.level, self.schema)
        
        self.assertEqual(self.tile_range.get_first_col(), 0, "tile_range.get_first_col()")
        self.assertEqual(self.tile_range.get_first_row(), 1, "tile_range.get_first_row()")
        self.assertEqual(self.tile_range.get_last_col(), 4, "tile_range.get_last_col()")
        self.assertEqual(self.tile_range.get_last_row(), 3, "tile_range.get_last_row()")

    def test_tile_to_world(self):
        print("UAxis: test_tile_to_world")
        tiles = []
        for x in range(int(self.tile_range.get_first_col()), int(self.tile_range.get_last_col())):            
            for y in range(int(self.tile_range.get_first_row()), int(self.tile_range.get_last_row())):
                tile = TileInfo()
                tile.set_extent(self.axisnormal.tile_to_world(TileRange(x,y,x,y), self.level, self.schema))
                tile.set_tile_index(TileIndex(x,y,self.level))
                if (Tile.__within_schema_extent(self.schema.get_extent(), tile.get_extent())):
                    tiles.append(tile)

if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    unittest.main()